/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.uoc.tdp.pac4.client.estadisticas;

import edu.uoc.tdp.pac4.beans.Matricula;
import edu.uoc.tdp.pac4.beans.Usuario;
import edu.uoc.tdp.pac4.client.PnlMain;
import edu.uoc.tdp.pac4.remote.Conexion;
import edu.uoc.tdp.pac4.remote.Estadisticas;
import edu.uoc.tdp.pac4.util.LanguageUtils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
/**
 *
 * @author eSupport Netbeans
 */
public class PnlFiltroCursos extends javax.swing.JDialog {

   private Estadisticas manager;
   private LanguageUtils language;
   private Usuario usuario;
   private java.awt.Frame parent;
    /**
     * Creates new form PnlFiltroCursos
     */
    public PnlFiltroCursos(java.awt.Frame parent, boolean modal,Estadisticas manager, LanguageUtils language, Usuario usr) {
        
        super(parent, modal);
        initComponents();
        setLocationRelativeTo(null);
        this.manager = manager;
        this.language = language;
        //Cargar textos
        
        btnAceptar.setText(language.getProperty("form.common.accept"));
        btnCancelar.setText(language.getProperty("form.common.close"));
        lblFecha.setText(language.getProperty("estadisticas.form.fechaInicio"));
        lblCursos.setText(language.getProperty("estadisticas.form.mostrarCursos"));
        opAbiertos.setText(language.getProperty("estadisticas.form.opAbiertos"));
        opFin.setText(language.getProperty("estadisticas.form.opFinalizados"));
        opTodos.setText(language.getProperty("estadisticas.form.opTodos"));
        this.setTitle(language.getProperty("estadisticas.form.estAlumno"));
                              
        opcionesMostrar.add(opFin);
        opcionesMostrar.add(opAbiertos);
        opcionesMostrar.add(opTodos);
        opTodos.setSelected(true);
        this.usuario=usr;
        this.parent=parent;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        opcionesMostrar = new javax.swing.ButtonGroup();
        lblFecha = new javax.swing.JLabel();
        txtData = new javax.swing.JTextField();
        btnAceptar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        lblCursos = new javax.swing.JLabel();
        opTodos = new javax.swing.JRadioButton();
        opFin = new javax.swing.JRadioButton();
        opAbiertos = new javax.swing.JRadioButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        lblFecha.setText("Fecha de inicio:");

        btnAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/tick-button.png"))); // NOI18N
        btnAceptar.setText("Aceptar");
        btnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarActionPerformed(evt);
            }
        });

        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/arrow-curve-180.png"))); // NOI18N
        btnCancelar.setText("Cerrar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lblCursos.setText("Mostrar sólo los cursos:");

        opTodos.setText("Todos");
        opTodos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                opTodosActionPerformed(evt);
            }
        });

        opFin.setText("Finalizados");

        opAbiertos.setText("Abiertos");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(opAbiertos)
                            .addComponent(opFin)
                            .addComponent(opTodos)))
                    .addComponent(lblCursos))
                .addContainerGap(42, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblCursos)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(opTodos)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(opFin)
                .addGap(3, 3, 3)
                .addComponent(opAbiertos)
                .addContainerGap(16, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(btnAceptar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnCancelar))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblFecha)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtData, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(17, 17, 17)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblFecha)
                            .addComponent(txtData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnAceptar)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(btnCancelar)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void opTodosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_opTodosActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_opTodosActionPerformed

    private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
        // TODO add your handling code here:

        //pasa los datos de filtro a al PnlListadoAlumno
        int opcio=0;

        if(opFin.isSelected())opcio=1;
        if(opAbiertos.isSelected())opcio=2;

        String txt=txtData.getText();
        Date data=null;

        try {

            if(txt.equals(""))
            {
                data=null;
            }
            else
            {

                SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");
                data = formato.parse(txt);
            }

            PnlListadoAlumno form = new PnlListadoAlumno(parent, true, manager, language, usuario, opcio,data);
            form.setLocationRelativeTo(null);
            form.setVisible(true);

        } catch (ParseException ex) {
            JOptionPane.showMessageDialog(null,
                language.getProperty("err.formatoData"),
                language.getProperty("app.title"),
                JOptionPane.ERROR_MESSAGE);
        }

    }//GEN-LAST:event_btnAceptarActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        // cierra el formulario

        this.dispose();
    }//GEN-LAST:event_btnCancelarActionPerformed

    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lblCursos;
    private javax.swing.JLabel lblFecha;
    private javax.swing.JRadioButton opAbiertos;
    private javax.swing.JRadioButton opFin;
    private javax.swing.JRadioButton opTodos;
    private javax.swing.ButtonGroup opcionesMostrar;
    private javax.swing.JTextField txtData;
    // End of variables declaration//GEN-END:variables
}
